package com.anyou.mall.pla.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.anyou.common.annotation.Log;
import com.anyou.common.core.controller.BaseController;
import com.anyou.common.core.domain.ApiResult;
import com.anyou.common.enums.BusinessType;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import com.anyou.mall.pla.domain.PlaReportType;
import com.anyou.mall.pla.service.IPlaReportTypeService;
import com.anyou.common.utils.poi.ExcelUtil;
import com.anyou.common.core.page.TableDataInfo;

/**
 * 举报类型Controller
 *
 * @author ylj
 * @date 2022-03-18
 */
@Api(tags = "举报类型")
@RestController
@RequestMapping("/pla/reportType")
public class PlaReportTypeController extends BaseController
{
    @Autowired
    private IPlaReportTypeService plaReportTypeService;

    /**
     * 查询举报类型列表
     */
    @ApiOperation("查询举报类型列表")
    @PreAuthorize("@ss.hasPermi('pla:reportType:list')")
    @GetMapping("/list")
    public TableDataInfo<List<PlaReportType>> list(PlaReportType plaReportType)
    {
        startPage();
        List<PlaReportType> list = plaReportTypeService.selectPlaReportTypeList(plaReportType);
        return getDataTable(list);
    }

    /**
     * 查询所有类型
     */
    @ApiOperation("查询所有举报类型")
    @PreAuthorize("@ss.hasPermi('pla:reportType:all')")
    @GetMapping("/all")
    public TableDataInfo<List<PlaReportType>> all()
    {
        return getDataTable(plaReportTypeService.selectPlaReportTypeList(new PlaReportType()));
    }

    /**
     * 导出举报类型列表
     */
    @ApiOperation("导出举报类型列表")
    @PreAuthorize("@ss.hasPermi('pla:reportType:export')")
    @Log(title = "举报类型", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PlaReportType plaReportType)
    {
        List<PlaReportType> list = plaReportTypeService.selectPlaReportTypeList(plaReportType);
        ExcelUtil<PlaReportType> util = new ExcelUtil<PlaReportType>(PlaReportType.class);
        util.exportExcel(response, list, "举报类型数据");
    }

    /**
     * 获取举报类型详细信息
     */
    @ApiOperation("获取举报类型详细信息")
    @PreAuthorize("@ss.hasPermi('pla:reportType:query')")
    @GetMapping(value = "/{reportTypeId}")
    public ApiResult<PlaReportType> getInfo(@PathVariable("reportTypeId") Long reportTypeId)
    {
        return ApiResult.success(plaReportTypeService.selectPlaReportTypeByReportTypeId(reportTypeId));
    }

    /**
     * 新增举报类型
     */
    @ApiOperation("新增举报类型")
    @PreAuthorize("@ss.hasPermi('pla:reportType:add')")
    @Log(title = "举报类型", businessType = BusinessType.INSERT)
    @PostMapping
    public ApiResult add(@RequestBody PlaReportType plaReportType)
    {
        return ApiResult.success(plaReportTypeService.insertPlaReportType(plaReportType));
    }

    /**
     * 修改举报类型
     */
    @ApiOperation("修改举报类型")
    @PreAuthorize("@ss.hasPermi('pla:reportType:edit')")
    @Log(title = "举报类型", businessType = BusinessType.UPDATE)
    @PutMapping
    public ApiResult edit(@RequestBody PlaReportType plaReportType)
    {
        return ApiResult.success(plaReportTypeService.updatePlaReportType(plaReportType));
    }

    /**
     * 删除举报类型
     */
    @ApiOperation("删除举报类型")
    @PreAuthorize("@ss.hasPermi('pla:reportType:remove')")
    @Log(title = "举报类型", businessType = BusinessType.DELETE)
    @DeleteMapping("/{reportTypeIds}")
    public ApiResult remove(@PathVariable Long[] reportTypeIds)
    {
        return ApiResult.success(plaReportTypeService.deletePlaReportTypeByReportTypeIds(reportTypeIds));
    }
}
